'use strict';
const uniID = require('uni-id-common')
exports.main = async (event, context) => {
	const uniIDIns = uniID.createInstance({
		context: context,
	})
	const res = await uniIDIns.checkToken(event.uniIdToken)
	const db = uniCloud.databaseForJQL({
		event,
		context
	});
	if (event._id == null) {
		return null
	}
	var userId = {
		user_id: res.uid
	}
	if (res.uid == '641af5fef43e603fbe9f5f53') {
		userId = {}
	}
	const info = await db.collection("item").where({
		_id: event._id,
		...userId
	}).get({
		getOne: true
	});
	await db.collection("delete_file").add({
		time: new Date().getTime(),
		...userId,
		url: info.data.url,
		icon: info.data.icon
	});
	await db.collection("item").where({
		...userId,
		_id: event._id
	}).remove();
	await db.collection('link').where({
		item_id: event._id,
		...userId
	}).remove()
	await db.collection('comment').where({
		item_id: event._id
	}).remove()
	await db.collection('good').where({
		item_id: event._id
	}).remove()
	await db.collection('order').where({
		item_id: event._id
	}).remove()
	await db.collection('rate').where({
		item_id: event._id
	}).remove()
	await db.collection('collect').where({
		item_id: event._id
	}).remove()
	return {
		msg: "删除成功",
		data: event._id
	}
};